package com.qf.handerException;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author Ypl
 * @version V1.0
 * @Project September-mavens
 * @Package com.qf.handerException
 * @Description:
 * @Date 2022/10/8 16:03
 */
@SuppressWarnings("all")
//@ControllerAdvice
public class MyExceprion02  {

    /**
     * 处理运行时异常
     * @param e
     * @return
     */

    @ExceptionHandler({
            RuntimeException.class
    })

    public ModelAndView handlerRuntimeException(RuntimeException e) {
        e.printStackTrace();
        ModelAndView mv = new ModelAndView();
        mv.addObject("error", "运行时异常");
        mv.setViewName("/error.jsp");
        return mv;
    }

    /**
     * 处理其他异常
     * @param e
     * @return
     */

    @ExceptionHandler({
            Exception.class
    })

    public ModelAndView handlerOtherException(Exception e) {
        e.printStackTrace();
        ModelAndView mv = new ModelAndView();
        mv.addObject("errorMsg", "其他异常");
        mv.setViewName("/error.jsp");
        return mv;
    }
}
